import { getPrice, setPrice } from '@/utils/storage'
import request from '@/utils/request'
import store from '@/store'
export default {
  namespaced: true,
  state () {
    return {
      price: getPrice()
    }
  },
  mutations: {
    setUserInfo (state, price) {
      state.price = price
      setPrice(state.price)
    }
  },
  actions: {
    async payPriceAction ({ commit }, price) {
      const userId = store.state.user.userInfo.userId
      const res = await request.post('/payPrice', {
        userId,
        price
      }, {
        headers: {
          Authorization: store.state.user.userInfo.token
        }
      }
      )
      console.log(res.data)
      commit('setUserInfo', price)
    }
  }
}
